package com.goldenautumn.prefabricate.activity.home

import android.content.Context
import android.graphics.Typeface
import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.core.content.ContextCompat
import com.blankj.utilcode.util.SizeUtils
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.DataBindingHolder
import com.goldenautumn.prefabricate.R
import com.goldenautumn.prefabricate.business.entity.TabInfoVo
import com.goldenautumn.prefabricate.databinding.ItemHomeTabBinding

class HomeTabAdapter : BaseQuickAdapter<TabInfoVo, DataBindingHolder<ItemHomeTabBinding>>() {

    var selectPosition = 0

    override fun onBindViewHolder(holder: DataBindingHolder<ItemHomeTabBinding>, position: Int, item: TabInfoVo?) {
        if(item == null) return
        var mBinding  = holder.binding
        var params = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,SizeUtils.dp2px(36f))
        when (holder.layoutPosition) {
            0 -> params.setMargins(SizeUtils.dp2px(16f), 0,0, 0)
            items.size - 1 -> params.setMargins(SizeUtils.dp2px(8f), 0, SizeUtils.dp2px(16f), 0)
            else -> params.setMargins(SizeUtils.dp2px(8f), 0,0, 0)
        }
        holder.itemView.layoutParams = params
//        mBinding.icon.loadImgUrl(item.icon)
        mBinding.title.text = "${item.title}"

        if(position == selectPosition){
            mBinding.title.setTextColor(ContextCompat.getColor(context,R.color.colorPrimary))
            mBinding.title.setTypeface(null, Typeface.BOLD)
            mBinding.content.shapeBuilder
                ?.setShapeSolidColor(ContextCompat.getColor(context,R.color.color_141e9459))
                ?.setShapeStrokeColor(ContextCompat.getColor(context,R.color.colorPrimary))
                ?.into(mBinding.content)
        } else {
            mBinding.title.setTextColor(ContextCompat.getColor(context,R.color.color_1D1F20))
            mBinding.title.setTypeface(null, Typeface.NORMAL)
            mBinding.content.shapeBuilder
                ?.setShapeSolidColor(ContextCompat.getColor(context,R.color.white))
                ?.setShapeStrokeColor(ContextCompat.getColor(context,R.color.color_efefef))
                ?.into(mBinding.content)
        }

    }

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): DataBindingHolder<ItemHomeTabBinding> {
        return DataBindingHolder(R.layout.item_home_tab,parent)
    }

}